﻿/* -------------------------------------------------------------------------
//	文件名		：	debugheader.h
//	创建者		：	
//	创建时间	：	2008-3-21 12:06:48 pm
//	功能描述	：	
//
//	$Id: $
// -----------------------------------------------------------------------*/
#ifndef __DEBUGHEADER_H__
#define __DEBUGHEADER_H__

// -------------------------------------------------------------------------

#ifdef _WIN32
#include <crtdbg.h>
#endif

#include <assert.h>

#ifdef __cplusplus
#else
#define false 0
#define true 1
#endif

#ifndef _DEBUG
	#define PROCESS_ERROR(x)	\
		do						\
		{						\
			if(!(x))			\
			goto Exit0 ;		\
		}while(0)
#else
#define PROCESS_ERROR(x) if (!(x)) { printf( "%s\n%s:%d\n", #x, __FILE__, __LINE__ ); goto Exit0; }
	/*#define PROCESS_ERROR(x)	\
		if (!(x))				\
		{						\
			goto Exit0;			\
		}						\*/

	#define PROCESS_LOOP_ERROR(x)	\
		if (!(x))					\
		{							\
			goto LoopExit0;			\
		}							\
		NULL;
#endif //_DEBUG

#define RETURN_ON_FAIL(exp)		\
	do {	\
		if (!(exp))	\
		{	\
			assert(false);	\
			return false;	\
		}	\
	} while(0)

#ifndef NULL
#ifdef __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif
#endif

#include "debugnew.h"

#ifdef _DEBUG

	#define TRACE(msg)	\
		do { \
			_CrtDbgReport(_CRT_WARN, NULL, NULL, NULL, "%s", msg); \
		} while(0)

//	#define TRACE0(msg)	\
//		do { \
//			_CrtDbgReport(_CRT_WARN, __FILE__, __LINE__, NULL, "%s", msg); \
//		} while(0)

//	#define TRACE1(msg, arg1)	\
//		do { \
//			_CrtDbgReport(_CRT_WARN, __FILE__, __LINE__, NULL, msg, arg1); \
//		} while(0)

//	#define TRACE2(msg, arg1, arg2)	\
//		do { \
//			_CrtDbgReport(_CRT_WARN, __FILE__, __LINE__, NULL, msg, arg1, arg2); \
//		} while(0)

//	#define TRACE3(msg, arg1, arg2, arg3)	\
//		do { \
//			_CrtDbgReport(_CRT_WARN, __FILE__, __LINE__, NULL, msg, arg1, arg2, arg3); \
//		} while(0)

	#define TRACE0(msg)	\
		do { \
			TCHAR szMsg[2048]; \
			wsprintf(szMsg, _T("%s(%d) : %s"), _T(__FILE__), __LINE__, msg); \
			OutputDebugString(szMsg); \
		} while(0)

	#define BARETRACE0(msg)	\
		do { \
			OutputDebugString(msg); \
		} while(0)

	#define TRACE1(msg, arg1)	\
		do { \
			TCHAR szMsg1[256], szMsg2[2048]; \
			wsprintf(szMsg1, msg, arg1); \
			wsprintf(szMsg2, _T("%s(%d) : %s"), _T(__FILE__), __LINE__, szMsg1); \
			OutputDebugString(szMsg2); \
		} while(0)

	#define BARETRACE1(msg, arg1)	\
		do { \
			TCHAR szMsg[256]; \
			wsprintf(szMsg, msg, arg1); \
			OutputDebugString(szMsg); \
		} while(0)

	#define TRACE2(msg, arg1, arg2)	\
		do { \
			TCHAR szMsg1[256], szMsg2[2048]; \
			wsprintf(szMsg1, msg, arg1, arg2); \
			wsprintf(szMsg2, _T("%s(%d) : %s"), _T(__FILE__), __LINE__, szMsg1); \
			OutputDebugString(szMsg2); \
		} while(0)

	#define BARETRACE2(msg, arg1, arg2)	\
		do { \
			TCHAR szMsg[256]; \
			wsprintf(szMsg, msg, arg1, arg2); \
			OutputDebugString(szMsg); \
		} while(0)

	#define TRACE3(msg, arg1, arg2, arg3)	\
		do { \
			TCHAR szMsg1[256], szMsg2[2048]; \
			wsprintf(szMsg1, msg, arg1, arg2, arg3); \
			wsprintf(szMsg2, _T("%s(%d) : %s"), _T(__FILE__), __LINE__, szMsg1); \
			OutputDebugString(szMsg2); \
		} while(0)

	#define BARETRACE3(msg, arg1, arg2, arg3)	\
		do { \
			TCHAR szMsg[256]; \
			wsprintf(szMsg, msg, arg1, arg2, arg3); \
			OutputDebugString(szMsg); \
		} while(0)

	#define TRACE0_ONCE(msg)	\
		do { \
			static int nCount = 0; \
			if (0 == nCount) \
			{ \
				nCount++; \
				TRACE0(msg); \
			} \
		} while(0)

	#define ASSERT_ONCE(f) \
		do { \
			static int nCount = 0; \
			if (!f && 0 == nCount) \
			{ \
				nCount++; \
				assert(FALSE); \
			} \
		} while(0)

	#define VERIFY(f)          assert(f)

#else	// #ifdef _DEBUG

	#define TRACE(msg)
	#define TRACE0(msg)
	#define TRACE1(msg, arg1)
	#define TRACE2(msg, arg1, arg2)
	#define TRACE3(msg, arg1, arg2, arg3)
	#define TRACE0_ONCE(msg)
	#define ASSERT_ONCE(f)

	#define VERIFY(f)          ((void)(f))

#endif	// #ifdef _DEBUG
// -------------------------------------------------------------------------
// $Log: $

#endif /* __DEBUGHEADER_H__ */
//Last line for linux

